package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Aspect
@Slf4j
public class MyJoinPoint {
    @Pointcut("execution(* com.itheima.service.impl.DeptServiceImpl.*(..))")
    public void myPointcut() {}

    @Around("myPointcut()")
    public Object myAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        //1.获取目标对象的类名
        String name = proceedingJoinPoint.getTarget().getClass().getName();
        log.info("获取目标对象的类名:{}", name);

        //2.获取目标方法的方法名
        String methodName = proceedingJoinPoint.getSignature().getName();
        log.info("获取目标方法的方法名:{}", methodName);

        //3.获取目标方法运行时传入的参数
        Object[] args = proceedingJoinPoint.getArgs();
        log.info("获取目标方法运行时传入的参数:{}", Arrays.toString(args));

        //4.执行目标方法
        Object proceed = proceedingJoinPoint.proceed();

        //5.获取目标方法的返回值
        log.info("目标方法的返回值：{}", proceed);

        return proceed;
    }
}
